package com.ygy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ygy.entity.Products;
import com.ygy.mapper.ProductsMapper;
import com.ygy.service.IProductsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 商品表 服务实现类
 * </p>
 *
 * @author Ye
 * @since 2024-03-14
 */
@Service
public class ProductsServiceImpl extends ServiceImpl<ProductsMapper, Products> implements IProductsService {

    @Autowired
    private ProductsMapper productsMapper;
    @Override
    public List<Products> findAllOnSale() {
        QueryWrapper<Products> queryWrapper = new QueryWrapper<>();
        // 假设ProductStatus枚举的在售状态值为1，根据实际情况调整
        queryWrapper.eq("status", 1);
        // 添加排序逻辑，按照productId字段倒序
        queryWrapper.orderByDesc("product_id");
        return productsMapper.selectList(queryWrapper);
    }
}
